(function () {
	admin.factory('removeFromList', ['$http','$uibModal','localStorageService',
		function($http,$uibModal,localStorageService){
			return function (option){
				var id = $('[name="ids"]:checked').val();
		    // var table = 'dept';
		    // var $scope = $scope;
		    // var modalConfig = {
		    //   title:'删除确认',
		    //   content:'您确定要删除该项？<br />\
		    //           <strong>此操作不可逆！</strong>',
		    // }
		    var modalConfig = option.modalConfig;
		    var $scope  = option.$scope;
		    var table  = option.table;
		    var modalInstance = $uibModal.open({
		      templateUrl: 'Modal.html',
		      controller:  function($scope,$uibModalInstance){
		        $scope.modal = modalConfig;
		        $scope.ok = function () {
		          $uibModalInstance.close( true );
		        };
		        $scope.cancel = function () {
		          $uibModalInstance.dismiss('cancel');
		        };
		      }
		    });
		    modalInstance.result.then(
			    // 确定执行
		    	function ( b ) {
			      if( b ) {
				      var notice = show_stack('loading');
			        $http
			        	.delete('/api/'+table+'/'+id)

			        	.success(function (data) {
			        		console.log( data );
				          $scope[table].splice($scope[table].indexOf($scope.map[table][id]),1);
				          localStorageService.set(table , $scope[table]);
				          notice.update(PNotify.prototype.myOpts['success-remove'])
				        })

				        .error(function (data) {
				          console.log(data);
				        })
			      }
			    },
			    // 取消执行
			    function () {

			      console.log( '取消时间' + new Date().getTime() );

			    });

			};// end of return
		}// end of factory
	])
})()